package hot100;

import java.util.HashSet;
import java.util.Set;

public class detectCycle3 {
    public mergeKLists.ListNode detectCycle(mergeKLists.ListNode head) {
        Set<mergeKLists.ListNode> hash = new HashSet<mergeKLists.ListNode>();
        while(head != null) {
            if(!hash.contains(head)){
                hash.add(head);
            }else {
                return head;
            }
            head = head.next;
        }
        return null;
    }
}
